Contents | Index | < Browse | Browse >

LETTERfopenULETTER Creates/opens a file.

Overview
#include <stdio.h>

fp = fopen(name, mode);

FILE *fp;
const char *name;
const char *mode;

Portability
ANSI

Description
Opens a file using the specified name and mode and returns a pointer to a FILE structure for access to this file. If the file could not be opened the function returns zero.

"mode" must be one of the following: "r": Opens an existing file for read access.
"w": Creates a new file and opens it for write access.
"a": Opens a file at its end for data to be appended.
"r+": Opens an existing file for read and write access.
"w+": Creates a new file and opens it for read and write access.
"a+": Opens a file at its end (append) for read and write access.

Append a "b" to the end of the strings if you wish to open a binary file. Without this "b" the file is treated as a text file. This makes no difference on the Amiga, however on other operating systems. For portable programming you should thus always choose the correct mode.